/**
 * 
 */
package com.icygen.eclipsetools.ui.wizards;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;

import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

import com.icygen.eclipsetools.ui.widgets.UriField;

/**
 * @author vanko
 *
 */
public class ProjectDataPage extends WizardPage implements KeyListener, ModifyListener
{
	private Text _title;
	private Composite container;

	private UriField _locationURI;

	  
	public ProjectDataPage()
	{
	    super("Project Data");
	    setTitle("Project Data");
	    setDescription("VS Tools Create Project Wizard First Page.");
	}

	
	/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
	 */
	@Override
	public void createControl(Composite parent) 
	{
		/*
		 * Init Layout
		 */
		container = new Composite(parent, SWT.NONE);
	    GridLayout layout = new GridLayout();
	    container.setLayout(layout);
	    layout.numColumns = 2;
	    
	    
		/*
		 * Init Text Fields
		 */
		Label labelTitle = new Label(container, SWT.NONE);
		labelTitle.setText("Project Title");
	    _title = new Text(container, SWT.BORDER | SWT.SINGLE);
	    _title.setText("");
	    _title.addKeyListener(this);
	    
	    
	    /*
	     * Init Location URI Field
	     */
	    Label labelLocationURI = new Label(container, SWT.NONE);
	    labelLocationURI.setText("Project Location");
	    _locationURI = new UriField(container, UriField.DIRECTORY);
	    _locationURI.setDialogInfo("dialogTitle", "dialogFilterName", null);
	    _locationURI.getTextField().addKeyListener(this);
	    _locationURI.getTextField().addModifyListener(this);
	    
	    
	    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
	    _title.setLayoutData(gd);
	    // Required to avoid an error in the system
	    setControl(container);
	    setPageComplete(false);
	}

	
	public String getTitle()
	{
	    return _title.getText();
	}
	
	public URI getLocationURI() throws URISyntaxException
	{
		return _locationURI.getURI();
	}

	
	public boolean useDefaults()
	{
		return false;
	}
	
	public void checkPageCopmplete()
	{
		if (!_title.getText().isEmpty() && !_locationURI.getText().isEmpty()) {
			setPageComplete(true);
		}
		else {
			setPageComplete(false);
		}
	}
	
	@Override
	public void keyPressed(KeyEvent e) 
	{
		
	}

	@Override
  	public void keyReleased(KeyEvent e) 
	{
		checkPageCopmplete();
	}
	
	@Override
	public void modifyText(ModifyEvent e)
	{ 
		checkPageCopmplete();
	}
}
